import 'package:dio/dio.dart';

class NetWorkGet {
  static void get(String url, Function callBack, {Map<String, dynamic> parameter, ResponseType responseType}) async {
    //代码
    Response response;
    if (parameter != null && parameter.isNotEmpty) {
      StringBuffer sb = new StringBuffer("?");
      parameter.forEach((key, value) {
        sb.write("$key" + "=" + "$value" + "&");
      });
      String paramStr = sb.toString();
      paramStr = paramStr.substring(0, paramStr.length - 1);
      url += paramStr;
    }

    try {
      //404
      response = await Dio().get(url, options: Options(responseType: responseType));
      //请求成功
      if (callBack != null) {
        callBack(response.data);
      }
    } on DioError catch (error) {
      print(error.type);
      /* 请求失败  */
      Map data = Map();
      data['error_code'] = 0;
      data['response'] = null;
      callBack(data);
    }
  }
}
